<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>微博详情页面</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        body {
            background-color: #f2f2f7; /* 温和的背景色 */
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            animation: fadeIn 1s ease-in-out;
        }

        .container {
            max-width: 800px;
            margin: 2rem auto;
            padding: 20px;
            background-color: #ffffff;
            border: 1px solid #ddd;
            border-radius: 10px;
            box-shadow: 0 5px 30px rgba(0, 0, 0, 0.1);
            animation: slideIn 1s ease-in-out;
        }

        h1 {
            text-align: center;
            margin-bottom: 1rem;
            font-size: 2.5rem;
            font-weight: 700;
            color: #4a4a4a;
        }

        h2 {
            margin-bottom: 10px;
            color: #1d1d1d;
            font-weight: 600;
        }

        p {
            margin: 5px 0;
            color: #666;
        }

        hr {
            border: 0;
            height: 1px;
            background-color: #e0e0e0;
            margin: 20px 0;
        }

        .comment-form {
            margin-top: 20px;
            padding: 20px;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: rgba(0, 0, 0, 0.1) 0 2px 10px;
            animation: fadeInUp 1s ease-in-out;
        }

        textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ccc;
            border-radius: 4px;
            resize: vertical;
            transition: border-color 0.3s, box-shadow 0.3s;
        }

        textarea:focus {
            border-color: #007BFF;
            box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
            outline: none;
        }

        input[type="button"] {
            width: 100%;
            margin-top: 10px;
            padding: 12px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.2s;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
        }

        input[type="button"]:hover {
            background-color: #0056b3;
            transform: translateY(-2px);
        }

        .comment-item {
            margin-bottom: 15px;
            padding: 15px;
            border: 1px solid #eaeaea;
            border-radius: 6px;
            background-color: #ffffff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 2px 8px;
            position: relative;
            transition: transform 0.2s, box-shadow 0.2s;
            animation: fadeInLeft 1s ease-in-out;
        }

        .comment-item:hover {
            transform: translateY(-2px);
            box-shadow: rgba(0, 0, 0, 0.1) 0 4px 15px;
        }

        .comment-item span {
            color: #007BFF;
            font-weight: bold;
        }

        .comment-item .created-at {
            position: absolute;
            right: 10px;
            bottom: 5px;
            font-size: 12px;
            color: #999;
        }

        /* 新增样式 */
        .nickname {
            color: mediumvioletred;
            font-weight: bold;
        }

        .comment-author {
            font-weight: bold;
            color: #007BFF;
        }

        .timestamp {
            color: #999;
            font-size: 12px;
        }

        .icon {
            margin-right: 5px;
        }

        .mode-toggle {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 10px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            transition: background-color 0.3s, transform 0.2s;
        }

        .mode-toggle:hover {
            background-color: #f9f9f9;
            transform: scale(1.1);
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @keyframes slideIn {
            from { transform: translateY(-20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        @keyframes fadeInUp {
            from { transform: translateY(20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        @keyframes fadeInLeft {
            from { transform: translateX(-20px); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }
    </style>
</head>

<body>

<div id="app" class="container">
    <div class="mode-toggle" @click="toggleMode">
        <i class="fas fa-moon"></i>
    </div>
    <h1>微博详情页面</h1>
    <h2><span class="nickname">{{ weibo.nickname }}</span>: {{ weibo.content }}</h2>
    <p>发布于: <i class="fas fa-clock icon"></i>{{ weibo.created }}</p>
    <hr>
    <div v-for="c in arr" class="comment-item">
        <h4>
            <span class="comment-author">{{ c.nickname }} 评论道:</span> {{ c.content }}
            <span class="created-at"><i class="fas fa-clock icon"></i>{{ c.created }}</span>
        </h4>
    </div>

    <div class="comment-form">
        <textarea cols="30" rows="3" placeholder="评论内容..." v-model="comment.content"></textarea>
        <input type="button" value="评论" @click="insert()">
    </div>
</div>

<!-- 引入 axios 和 Vue 框架 -->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "#app",
        data: {
            weibo: {},
            comment: { content: "" },
            arr: [],
            isDarkMode: false
        },
        methods: {
            insert() {
                v.comment.weiboId = v.weibo.id;
                axios.post("/v1/comment/insert", v.comment).then(function (response) {
                    if (response.data === 1) {
                        location.reload(); // 刷新页面
                    } else {
                        alert("请先登录");
                        location.href = "/login.html";
                    }
                }).catch(function (error) {
                    console.error('Comment insertion failed:', error);
                    alert("评论失败，请稍后再试");
                });
            },
            toggleMode() {
                this.isDarkMode = !this.isDarkMode;
                document.body.classList.toggle('dark-mode', this.isDarkMode);
            }
        },
        created: function () {
            const searchParams = new URLSearchParams(location.search);
            const weiboId = searchParams.get('id');

            axios.get(`/v1/weibo/selectById?id=${weiboId}`).then(function (response) {
                v.weibo = response.data;
            }).catch(function (error) {
                console.error('Failed to get weibo data:', error);
                alert("加载微博失败，请稍后再试");
            });

            axios.get(`/v1/comment/selectByWeiboId?id=${weiboId}`).then(function (response) {
                v.arr = response.data;
            }).catch(function (error) {
                console.error('Failed to get comments:', error);
                alert("加载评论失败，请稍后再试");
            });
        }
    });
</script>

<style>
    .dark-mode {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    .dark-mode .container {
        background-color: #2a2a2a;
        border-color: #4a4a4a;
    }

    .dark-mode .comment-form {
        background-color: #3a3a3a;
        border-color: #4a4a4a;
    }

    .dark-mode .comment-item {
        background-color: #3a3a3a;
        border-color: #4a4a4a;
    }

    .dark-mode .comment-item .created-at,
    .dark-mode .timestamp {
        color: #999;
    }

    .dark-mode .mode-toggle {
        background-color: #2a2a2a;
        border-color: #4a4a4a;
    }

    .dark-mode .mode-toggle i {
        color: #e0e0e0;
    }
</style>

</body>
</html>